package logic

import (
	"context"
	"github.com/pkg/errors"
	"mall/app/product/model"
	"mall/common/xerr"

	"mall/app/product/cmd/rpc/internal/svc"
	"mall/app/product/cmd/rpc/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateBrandLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateBrandLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateBrandLogic {
	return &UpdateBrandLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// UpdateBrand 更新品牌
func (l *UpdateBrandLogic) UpdateBrand(in *pb.UpdateBrandReq) (*pb.EmptyResp, error) {
	err := l.svcCtx.BrandModel.Update(l.ctx, &model.PmsBrand{
		BrandId:     in.BrandId,
		Name:        in.Name,
		Logo:        in.Logo,
		Descript:    in.Descript,
		ShowStatus:  in.ShowStatus,
		FirstLetter: in.FirstLetter,
		Sort:        in.Sort,
	})
	if err != nil {
		return nil, errors.Wrapf(xerr.NewErrorWithCode(xerr.DbError), "BrandModel.Update err: %v", err)
	}
	return &pb.EmptyResp{}, nil
}
